$(function() {
    
    $("#getCode").on("tap", getUPCode);
    $("#modifyBtn").on("tap", function() {
        var sureNewPassword = $("input[name='sureNewPass']").val();
        var data = {
            oldPassword: $("input[name='originPass']").val(),
            newPassword: $("input[name='newPass']").val(),
            vCode: $("input[name='checkCode']").val()
        }
        if (!data.oldPassword) {
            mui.toast('请输入密码');
            return;
        }
        if (!data.newPassword) {
            mui.toast('请输入确认密码');
            return;
        }
        if (data.newPassword != sureNewPassword) {
            mui.toast('两次密码输入的不相同');
            return;
        }
        if (!/^\d{6}$/.test(data.vCode)) {
            mui.toast('验证码输入的格式不正确');
            return;
        }
        $.ajax({
            type: 'post',
            url: ajaxUrl('updatePassword'),
            data: data,
            beforeSend: function() {
                $("#modifyBtn").html("提交中.....");
            },
            success: function(result) {
                $("#modifyBtn").html("确认修改密码");
                // console.log(result);
                if (result.error == 400) {
                    // location.href = "login.html";
                    mui.toast("修改失败, 未登录");
                } else if (result.success) {
                    mui.toast("修改成功, 请重新登录");
                    setTimeout(function() {
                        location.href = "login.html";
                    }, 2000);
                }
            }
        })
    })
})